package net.yla.smartbus.core.util;

import com.vip.vjtools.vjkit.time.DateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author : yanglei
 * @Date : Created in 15:31 2020/8/13
 * @description :
 */
@Component
public class UploadExcelUtils {

    /**
     * 行数
     */
    private int totalRows = 0;
    /**
     * 列数
     */
    private int totalCells = 0;

    /**
     * 错误提示信息
     */

    private String errorMsg;


    public UploadExcelUtils() {
    }

    public int getTotalRows() {
        return totalRows;
    }

    public void setTotalRows(int totalRows) {
        this.totalRows = totalRows;
    }

    public int getTotalCells() {
        return totalCells;
    }

    public void setTotalCells(int totalCells) {
        this.totalCells = totalCells;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    public Date finaStringDateToDate(String value) {
        Date date = null;
        boolean status = value.contains("/");
        if (!value.equals("")) {
            if (value.length() == 5 || !status) {
                Calendar calendar = new GregorianCalendar(1900, 0, -1);
                Date da = calendar.getTime();
                date = DateUtil.addDays(da, Integer.parseInt(value.trim()));
            } else if (value.length() == 8 || status) {
                DateFormat df = new SimpleDateFormat("yyyy/MM/dd");
                try {
                    date = df.parse(value);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
        return date;
    }

    public Date StringDateToDate(String stringDate) {
        Date date = null;
        if (!stringDate.equals("")) {
            Calendar calendar = new GregorianCalendar(1900, 0, -1);
            Date da = calendar.getTime();
            date = DateUtil.addDays(da, Integer.parseInt(stringDate.trim()));
        }
        return date;
    }

    public Integer stringToInteger(String value) {
        Integer integerValue = null;
        if (!value.equals("")) {
            integerValue = Integer.valueOf(value);
        }
        return integerValue;
    }

    Boolean stringvalueIsNotNull(String value) {
        Boolean flag = false;
        if (!value.equals("")) {
            flag = true;
        }
        return flag;
    }

}
